Skip to content

Conversation

@JohnRichard4096
Copy link
Member

@JohnRichard4096 JohnRichard4096 commented Oct 20, 2025

Sourcery 总结

重构命令处理器和数据持久化,以提高一致性并支持 UTF-8

改进:

  • 标准化处理程序签名以使用 id, operation, target, value,并将 node 参数重命名为 target
  • 重命名并重组命令:chat_group, perm_group, user,并简化命令组设置
  • 优化 parse_command 中的参数解析,并改进命令执行流程中的错误处理

杂项任务:

  • 将 config, data_manager 和 nodelib 中的 TOML 和 JSON 文件 I/O 切换为 UTF-8 文本模式
  • 添加 Permissions.from_perm_str 方法并调整 permissions_str 的导出
  • 将插件版本提升至 0.1.0
Original summary in English

Summary by Sourcery

Refactor command handlers and data persistence for better consistency and UTF-8 support

Enhancements:

  • Standardize handler signature to use id, operation, target, value and rename node parameters to target
  • Rename and reorganize commands: chat_group, perm_group, user and simplify command group setup
  • Refine argument parsing in parse_command and improve error handling in command execution flows

Chores:

  • Switch TOML and JSON file I/O to UTF-8 text mode across config, data_manager, and nodelib
  • Add Permissions.from_perm_str method and adjust permissions_str dumping
  • Bump plugin version to 0.1.0

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 20, 2025

🧙 Sourcery 已完成对您的拉取请求的审查!


提示和命令

与 Sourcery 交互

  • 触发新的审查: 在拉取请求上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 通过回复审查评论,要求 Sourcery 从中创建一个 issue。您也可以回复审查评论并带上 @sourcery-ai issue 来从中创建一个 issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置写入 @sourcery-ai,即可随时生成标题。您也可以在拉取请求上评论 @sourcery-ai title,随时(重新)生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任意位置写入 @sourcery-ai summary,即可随时在您想要的位置生成 PR 摘要。您也可以在拉取请求上评论 @sourcery-ai summary,随时(重新)生成摘要。
  • 生成审查者指南: 在拉取请求上评论 @sourcery-ai guide,随时(重新)生成审查者指南。
  • 解决所有 Sourcery 评论: 在拉取请求上评论 @sourcery-ai resolve,以解决所有 Sourcery 评论。如果您已处理所有评论并且不想再看到它们,这会很有用。
  • 驳回所有 Sourcery 审查: 在拉取请求上评论 @sourcery-ai dismiss,以驳回所有现有的 Sourcery 审查。如果您想从头开始进行新的审查,这会特别有用——别忘了评论 @sourcery-ai review 来触发新的审查!

自定义您的体验

访问您的 仪表板 以:

  • 启用或禁用审查功能,例如 Sourcery 生成的拉取请求摘要、审查者指南以及其他功能。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English

🧙 Sourcery has finished reviewing your pull request!


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你好 - 我已经审查了你的修改,它们看起来很棒!

AI 代理的提示
请解决此代码审查中的评论:

## 单独评论

### 评论 1
<location> `src/nonebot_plugin_liteperm/nodelib.py:109-110` </location>
<code_context>
             self.permissions_data = json.load(f)
         self.__dump_to_str(overwrite=True)

+    def from_perm_str(self, perm_str: str):
+        for line in perm_str.split("\n"):
+            if line.strip() == "":
+                continue
</code_context>

<issue_to_address>
**issue:** 新的 'from_perm_str' 方法未能稳健地处理格式错误的行。

没有空格的行将在 split 时导致 ValueError。添加验证或错误处理以跳过或报告这些情况,并避免运行时异常。
</issue_to_address>

### 评论 2
<location> `src/nonebot_plugin_liteperm/commands/cmd_utils.py:18` </location>
<code_context>
async def parse_command(
    matcher: Matcher, args: Message = CommandArg()
) -> tuple[str, str, str, str, str]:
    """统一参数解析器"""
    args_list = args.extract_plain_text().strip().split(maxsplit=5)

    # 参数校验
    if len(args_list) < 1:
        await matcher.finish("❌ 缺少ID")
    if len(args_list) < 3:
        await matcher.finish("❌ 参数不足,需要至少3个参数")

    id = args_list[0]
    action_type = args_list[1]
    operation = args_list[2]
    target = args_list[3] if len(args_list) >= 4 else ""
    value = args_list[4] if len(args_list) == 5 else ""

    return id, action_type, operation, target, value

</code_context>

<issue_to_address>
**issue (代码质量):** 不要赋值给内置变量 `id` ([`avoid-builtin-shadow`](https://docs.sourcery.ai/Reference/Default-Rules/comments/avoid-builtin-shadow/))

<br/><details><summary>解释</summary>Python 有许多 `内置` 变量:构成语言一部分的函数和常量,例如 `list``getattr``type`
(参见 https://docs.python.org/3/library/functions.html)。
在语言中,重新绑定此类变量是有效的:

```python
list = [1, 2, 3]
```
然而,这被认为是糟糕的做法。
- 它会混淆其他开发人员。
- 它会混淆语法高亮显示器和 linter。
- 这意味着你不能再将该内置函数用于其原始目的。

你如何解决这个问题?

将变量重命名为更具体的内容,例如 `integers`。
在紧要关头,`my_list` 和类似名称是约定俗成的
占位符。</details>
</issue_to_address>

Sourcery 对开源免费 - 如果你喜欢我们的评论,请考虑分享它们 ✨
帮助我更有用!请点击每个评论上的 👍 或 👎,我将使用反馈来改进你的评论。
Original comment in English

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/nonebot_plugin_liteperm/nodelib.py:109-110` </location>
<code_context>
             self.permissions_data = json.load(f)
         self.__dump_to_str(overwrite=True)

+    def from_perm_str(self, perm_str: str):
+        for line in perm_str.split("\n"):
+            if line.strip() == "":
+                continue
</code_context>

<issue_to_address>
**issue:** The new 'from_perm_str' method does not handle malformed lines robustly.

Lines without a space will cause a ValueError on split. Add validation or error handling to skip or report these cases and avoid runtime exceptions.
</issue_to_address>

### Comment 2
<location> `src/nonebot_plugin_liteperm/commands/cmd_utils.py:18` </location>
<code_context>
async def parse_command(
    matcher: Matcher, args: Message = CommandArg()
) -> tuple[str, str, str, str, str]:
    """统一参数解析器"""
    args_list = args.extract_plain_text().strip().split(maxsplit=5)

    # 参数校验
    if len(args_list) < 1:
        await matcher.finish("❌ 缺少ID")
    if len(args_list) < 3:
        await matcher.finish("❌ 参数不足,需要至少3个参数")

    id = args_list[0]
    action_type = args_list[1]
    operation = args_list[2]
    target = args_list[3] if len(args_list) >= 4 else ""
    value = args_list[4] if len(args_list) == 5 else ""

    return id, action_type, operation, target, value

</code_context>

<issue_to_address>
**issue (code-quality):** Don't assign to builtin variable `id` ([`avoid-builtin-shadow`](https://docs.sourcery.ai/Reference/Default-Rules/comments/avoid-builtin-shadow/))

<br/><details><summary>Explanation</summary>Python has a number of `builtin` variables: functions and constants that
form a part of the language, such as `list`, `getattr`, and `type`
(See https://docs.python.org/3/library/functions.html).
It is valid, in the language, to re-bind such variables:

```python
list = [1, 2, 3]
```
However, this is considered poor practice.
- It will confuse other developers.
- It will confuse syntax highlighters and linters.
- It means you can no longer use that builtin for its original purpose.

How can you solve this?

Rename the variable something more specific, such as `integers`.
In a pinch, `my_list` and similar names are colloquially-recognized
placeholders.</details>
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@JohnRichard4096 JohnRichard4096 merged commit 440d683 into main Oct 20, 2025
2 checks passed
@JohnRichard4096 JohnRichard4096 deleted the refactor branch October 20, 2025 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants